import Vue from 'vue';//引入Vue对象，因为要用它的use
import Router from 'vue-router'//引入vue-router
//引入你需要配置的组件
import MyJD from '@/components/JH/MyJD.vue'
import Myorder from '@/components/JH/Myorder.vue'
import setting from '@/components/JH/setting.vue'
import received from '@/components/JH/received.vue'
import MyHome from '@/components/JH/MyHome'
import { Toast } from 'vant';

Vue.use(Toast);


Vue.use(Router);

const router = new Router({
    routes: [
        //重定向到主页
        {
            path: '/',
            redirect: '/MyHome',

        },
        //主页
        {
            path: '/MyHome',
            component: MyHome
        },
        //主页秒杀详情
        {
            path: '/seckill',
            component: () => import('@/components/LH/view/seckill')
        },

        //个人信息
        {
            path: '/MyJD',
            component: MyJD,
            meta: { isAuth: true, }
        },
        //待付款
        {
            path: '/Myorder',
            component: Myorder
        },
        //个人信息设置
        {
            path: '/setting',
            component: setting
        },
        //账户安全
        {
            path: '/mysecurity',
            component: () => import('@/components/CJS/mysecurity(账户安全)/mysecurity.vue')
        },
        //隐私设置
        {
            path: '/privacys',
            component: () => import('@/components/CJS/privacy(隐私设置)/privacys.vue')
        },
        //我的足迹
        {
            path: '/record',
            component: () => import('@/components/LH/view/record.vue')
        },
        //待收货
        {
            path: '/received',
            component: received
        },
        //退换，售后
        {
            path: '/mysales',
            component: () => import('@/components/CJS/Asales(售后）/mysales.vue')
        },
        //全部资产
        {
            path: '/asset',
            component: () => import('@/components/CJS/asset(全部资产)/asset.vue')
        },

        //分类页面
        {
            path: "/ClassifyPage",
            component: () => import('@/components/WKQ/view/ClassifyPage.vue')
        },
        //登录页面
        {
            path: "/LoginPage",
            component: () => import('@/components/WKQ/view/LoginPage.vue')
        },
        //注册页面
        {
            path: "/Register",
            component: () => import('@/components/WKQ/view/Register.vue')
        },
        //购物车页面
        {
            path: "/ShoppingCart",
            component: () => import('@/components/WKQ/view/ShoppingCart.vue')
        },
        //搜索页面
        {
            path: '/Searchs',
            component: () => import('./../components/WHE/view/SearchS.vue'),
            name: 'Recentsearches',
            meta: {
                keepAlive: true
            }
        },
        //产品详情
        {
            path: '/ProductDetails',
            component: () => import('./../components/WHE/view/ProductDetails.vue')
        },
        {
            path: '/ProductDetails1',
            component: () => import('./../components/WHE/view/ProductDetails1.vue')
        },
        //京东生鲜页面
        {
            path: '/JDFreshPage',
            component: () => import('./../components/WKQ/view/JDFreshPage.vue')
        },
        //京豆页面
        {
            path: '/JingDouPage',
            component: () => import('./../components/WKQ/view/JingDouPage.vue')
        },
        // 搜索后
        {
            path: '/Searchk',
            component: () => import('./../components/WHE/view/Searchk.vue')
        },

        //我的红包页面
        {
            path: '/RedPacketPage',
            component: () => import('./../components/WKQ/view/RedPacketPage.vue')
        },
        //数码电器
        {
            path: '/cybers',
            component: () => import('./../components/CJS/cybers.vue')
        },
        //我的地址
        {
            path: '/Myaddress',
            component: () => import('@/components/JH/Myaddress.vue')
        },
        //新增地址
        {
            path: '/addaddress',
            component: () => import('@/components/JH/addaddress.vue')
        },
        //编辑地址
        {
            path: '/editaddress',
            component: () => import('@/components/JH/editaddress.vue')
        },
        //新百货页面
        {
            path: '/newstore',
            component: () => import('@/components/JH/newstore.vue')
        },
        //京东新百货
        {
            path: '/newgoods',
            component: () => import('@/components/CJS/newgoods.vue')
        },


        //404页面
        {
            path: '*',
            name: 'no',
            component: () => import('@/components/WKQ/view/NoPage.vue')
        },
        // 京东超市界面
        {
            path: '/JingDongSupermarket',
            component: () => import('./../components/WHE/view/JingDongSupermarket.vue')
        },
        // 我的预约界面
        {
            path: '/MyAppointment',
            component: () => import('./../components/WHE/view/MyAppointment.vue')
        },
        // 客户服务
        {
            path:'/CustomerService',
            component:()=> import('./../components/WHE/view/CustomerService.vue')
        },
        //优惠卷
        {
            path:'/coupon',
            component:()=>import('@/components/LH/view/coupon.vue')
        },
        //白条
        {
            path:'/baitiao',
            component:()=>import('@/components/LH/view/baitiao.vue')
        },
        //附近好店
        {
            path:'/store',
            component:()=>import('@/components/LH/view/store.vue')
        }
    ],


})


router.beforeEach((to, from, next) => {
    if (to.meta.isAuth) {     //判断是否需要鉴权
        if (sessionStorage.getItem('token')) {
            next();
        } else {
            Toast('不好意思，您还未登录，请先去登录');
            next('/LoginPage')
        }
    } else {
        next()
    }


})

//导出
export default router;
